﻿using sipfe.Controllers.Base;
using sipfe.model.dataAccess;
using sipfe.service.mante;
using sipfe.util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace sipfe.Areas.Mante.Controllers
{
    public class PoliticaController : BaseSipfeController
    {
        string Titulo = "GESTIÓN Y MANTENIMIENTO DE POLITICAS";
        string paginaold = "SinRegistros";
        public ActionResult IndexCab()
        {
            ViewBag.TITULO = Titulo;
            //cargaCatlogos1();
            ViewBag.nIdeConvocatoria = null;
            return View("PoliticaManteInp");
        }
        public ActionResult PoliticaInp()
        {
            ViewBag.TITULO = Titulo;
            //cargaCatlogos1();
            return View();
        }

        [HttpPost]
        public ActionResult AddNuevaPolitica(SIPMaePolitica sipMaePolitica)
        {
            //if (ModelState.IsValid)
            //{
            string tipoPoli = Request.Form["nIdeMedida"];
            string tipoMeta = Request.Form["nIdeMeta"];
            string vDescrMedida = Request.Form["vDescrMedida"];
            string valorMeta = Request.Form["valorMeta"];
            string dFecMeta = Request.Form["dFecMeta"];

            PoliticaService politicaService = new PoliticaService();
            String[] rpta = politicaService.AddNuevaPoliticaService(sipMaePolitica, tipoPoli, tipoMeta, vDescrMedida, valorMeta, dFecMeta);
            return RedirectToAction("NuevaPoliticaRpta", new { nIdePoli = rpta[0] });
            //}
            return View("PoliticaInp", sipMaePolitica);

        }

        public ViewResult NuevaPoliticaRpta(decimal nIdePoli)
        {
            PoliticaService cS = new PoliticaService();
            return View("PoliticaManteInp");
        }

        private void cargaCatlogos()
        {
            ViewBag.PaisEmisor = formaSelectCompendio(Constante.getInstance().N_IDE_TABLA_PAIS_EMISOR);
            ViewBag.TipoDocIdent = formaSelectCompendio(Constante.getInstance().N_IDE_TABLA_TIPO_DOC_IDENTIFICACION);
        }
        
        public ViewResult ListaPoliticaById(int nIdePoli)
        {
            PoliticaService cS = new PoliticaService();
            SIPMaePolitica conv = new SIPMaePolitica();
            conv = cS.findSIPMaePoliticaByIdService(nIdePoli);
            ViewBag.nIdePoli = nIdePoli;
            return View("ListaPoliticaById", conv);
        }

        public ViewResult ListarPolitica(string fec_IniVig, string fec_FinVig, string ide_TipoPoli)
        {
            PoliticaService cS = new PoliticaService();
            IList<dynamic> listaPoli = cS.ListarPoliticaService(fec_IniVig, fec_FinVig, ide_TipoPoli);

            if (listaPoli.Count > 0) _pagina = "ListarPoliticaDet";
            return View(_pagina, listaPoli);
        }

    }
}
